package com.lanswon.controller.admin;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lanswon.common.util.CreateImageCode;
import com.lanswon.service.LoginService;

@Controller
@RequestMapping("admin")
public class AdminLoginController {
	@Autowired
	private LoginService loginService;

	@RequestMapping("")
	public String adminLogin() {// login

		return "admin/login";
	}

	@RequestMapping("loginCheck")
	@ResponseBody
	public Map<String, Object> loginCheck(String username, String password, String code, HttpServletRequest request) {

		Map<String, Object> viewMap = loginService.loginCheck(username, password, code, request);

		return viewMap;
	}

	/**
	 * 生成验证码
	 */
	@RequestMapping("/captcha")
	public void captcha(HttpServletResponse response, HttpSession session) throws IOException {
		CreateImageCode vCode = new CreateImageCode(116, 36, 5, 10);
		session.setAttribute("code", vCode.getCode());
		OutputStream sos = response.getOutputStream();
		vCode.write(sos);
	}

}
